function accuracy = cca_window_condition_compare(Fs,stimulusFreq,nHarmonics,epochLengths,stepTime,excludeTrial,varargin)
%画出各类数据在指定谐波次数下，正确率随窗长的变化情况
%---input---
%Fs：采样率,单位Hz，e.g.500
%stimulusFreq：刺激频率，单位Hz，e.g.[7.5 9.0 10.5 12.0]
%nHarmonics:谐波次数
%epochLengths：窗长范围，单位s，e.g.0.5:0.1:2.0
%stepTime：滑窗长度，单位s，e.g.0.2
%varargin：输入数据，第一个维度为session，第二个维度为stimulus，第三个维度为trial，第四个维度为channel，第五个维度为samplepoints，可以输入多组数据表示不同condition下的数据
%excludeTrial: 移除的trial，每一行表示一个trial，格式为[stimulus condition session trial]
%---output---
%accuracy：正确率，size1窗长，size2种类，size3刺激频率


for L = 1:length(epochLengths)
    epochTime = epochLengths(L);
    for condition = 1:nargin-6
        SSVEPdata = varargin{condition};
        for stimulus = 1:size(SSVEPdata,2)
            accuracy_session = [];
            for session = 1:size(SSVEPdata,1)
                avl_trial_index = 0;
                classify_result = [];
                for trial = 1:size(SSVEPdata,3)
                    %移除错误数据
                    avl_trial_flag = 1;
                    for i = 1:size(excludeTrial,1)
                        excludei = excludeTrial(i,:);
                        if(all([stimulus condition session trial] == excludei))
                            avl_trial_flag = 0;
                            break;
                        end
                    end
                    if(~avl_trial_flag)
                        continue;
                    end
                    avl_trial_index = avl_trial_index + 1;
                    epoch = SSVEPdata(session,stimulus,trial,:,:);  %单一trial数据
                    epoch = reshape(epoch,size(SSVEPdata,4),size(SSVEPdata,5));
                    windowCount = floor((size(epoch,2) - epochTime * Fs + 1) / (stepTime * Fs));
                    parfor window = 1:windowCount
                        classify_result(avl_trial_index,window) = canonical_correlation_analysis(epoch(:,int32((window-1) * stepTime * Fs + 1):int32((window-1) * stepTime * Fs + epochTime * Fs)),stimulusFreq,nHarmonics,epochTime,Fs);
                        %                         display(['epochLength: ', num2str(epochTime), ' nHarmonics: ', num2str(nHarmonics),' Condition: ', num2str(condition), ...
                        %                             ' Stimulus: ', num2str(stimulus), ' Session: ', num2str(session), ' Trial: ', num2str(trial), ' Window: ', num2str(window), ...
                        %                             ' Result: ', num2str(classify_result(avl_trial_index,window))]);
                    end %window
                end %trial
                accuracy_session(session) = sum(classify_result == stimulus, 'all') / (size(classify_result,1) * size(classify_result,2));
            end %session
            accuracy(L,condition,stimulus) = mean(accuracy_session);
        end %stimulus
        display(['epochLength: ', num2str(epochTime), ' nHarmonics: ', num2str(nHarmonics),' Condition: ', num2str(condition),  ' Accuracy: ',num2str(mean(accuracy(L,condition,:),3))]);
    end %condition
end %epochLengths


%画图
%各种情况的比较,最多三种,并且此时只能有一种谐波
acc = mean(accuracy,3);
acc = reshape(acc,[],nargin-6);
figure;
for c = 1:nargin-6
    plot(epochLengths,acc(:,c),'linewidth',2);
    hold on;
end
xlabel('Epoch Length [s]');
ylabel('Accuracy %');
legend('Static','Yaw','Pitch');
set(gca, 'linewidth', 2, 'fontsize', 20, 'fontname', 'times');


end

